<script>
function get_invoiceno(id_user){
		$.post("<?= site_url('accounts/payment/get_invoiceno')?>",{ id_user:id_user }, function(msg){
		if(msg){
				jQuery('#areas').empty().append(msg);
				jQuery('#areas').trigger("liszt:updated");
			//document.getElementById("areas").innerHTML = msg;	

		}
		
		})	
}

function get_amount(id_purchase){
		$.post("<?= site_url('accounts/payment/get_amount')?>",{ id_purchase : id_purchase}, function(msg){
		if(msg){
				$("#debit_amount").val(msg);	

		}
		
		})	
}

function get_check(id,type){
	if(id.checked){
		if(type==1){
			$('.dd').show()		
		}else{
			$('.dd').hide()
			
		}
		
	}	

}

</script>
<h2 style="background-color:#368EE0; color:white; font-size:20px; padding:5px;">ADD Payment</h2>

<br>
<br>

<div id="infoMessage"><?php echo $message;?></div>
<?php echo form_open("accounts/payment/create_payment");?>

     <table width="48%" align="center" class="table-condensed">  
        <tr>
         <td> <b>Supplier:</b> </td>
         <td>
     <select name="id_user" onchange="get_invoiceno(this.value);" class="chzn-select">
    <option value="0">-- Supplier -- </option>
    <?php foreach ($suppliers as $supplier) {?>
    <option value="<?=$supplier->id?>" <?php 
	if(isset($edit)) {
	if($edit['user_id'] == $branch->id)
	{
		echo 'selected = "selected"';
		}
	}
	else {
	echo set_select('id_user',$supplier->id);
	}
	?> ><?= $supplier->name;?></option >
    <?php } ?>
    </select></td>
    </tr>
	<tr>
	<td><b>Voucher No</b></td>
	<td><select id="areas" class=" chzn-select" name="voucher_no" onchange="get_amount(this.value);">
	</select></td>
	</tr>
	<tr>
	<td><b>Debit Amount</b></td><td><input type="text"  id="debit_amount"  name="debit_amount" ></td>
	</tr>
	<tr>
	<td><b>Deposit By</b></td><td><label class="radio"><input type="radio" id="payment_type" value='0' onchange="get_check(this, this.value);"  name="payment_type">:Cash&nbsp;&nbsp;&nbsp;</label><label class="radio"><input type="radio" value='1' id="payment_ttype" onchange="get_check(this, this.value);"  name="payment_type">:Cheque/Draft</label></td>
	</tr>
	<tr class="dd"  style="display: none" >
	<td><b>Checque/draft No</b></td>
	<td><input type="text" name="cheque_no"></td>
	</tr>
	<tr class="dd" style="display: none">
	<td><b>Select Bank</b></td>
	<td>  <select name="bank_name"  class="chzn-select">
    <option value="">-- bank -- </option>
    <?php foreach ($banks as $bank) {?>
    <option value="<?=$bank->name?>" <?php 
	if(isset($edit)) {
	if($edit['user_id'] == $branch->id)
	{
		echo 'selected = "selected"';
		}
	}
	else {
	echo set_select('id_user',$supplier->id);
	}
	?> ><?= $bank->name;?></option >
    <?php } ?>
    </select></td>
	</tr>
	
	<tr> <td><b>  Date: </b></td>
            <td><?php echo form_input($date);?></td>
    </tr>
<tr><td>&nbsp;</td> <td><p align="center"><?php echo form_submit('submit', 'Create Payment', 'class="btn btn-success"');?></p></td></tr>
</table>
<?php echo form_close();?>
